﻿using EA.Common;
using EA.DAO;
using EA.DTO;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EA.BA
{
    public class AuctionLogBA:ObjectBA
    {
        public List<AuctionLogTO> GetAllAuctionLogByProductID(int productID)
        {
            List<AuctionLogTO> auctionList = new List<AuctionLogTO>();
            AuctionLogDA auctionDA = new AuctionLogDA(ObjectBA.ConnectionString);
            DataTable table = auctionDA.GetAllAuctionLogByProductID(productID);
            for (int i = 0; i < table.Rows.Count; i++)
            {
                AuctionLogTO auctionTO = new AuctionLogTO();
                auctionTO.ID=Converts.getValueInteger("ID",i,table);
                auctionTO.Price = Converts.getValueDecimal("Price",i,table);
                auctionTO.ProductID = Convert.ToInt32(table.Rows[i]["ProductID"]);
                auctionTO.BuyerID = Convert.ToInt32(table.Rows[i]["BuyerID"]);
                auctionTO.BidDate = Converts.getValueDateTime("BidDate",i,table);
                auctionTO.Status = Converts.getValueInteger("Status",i,table);
                auctionTO.Emails = Converts.getValueString("Email",i,table);
                auctionList.Add(auctionTO);
            }
            return auctionList;
        }

        public int  GetEndBuyerId(int productID)
        {
            List<AuctionLogTO> auctionList = new List<AuctionLogTO>();
            AuctionLogDA auctionDA = new AuctionLogDA(ObjectBA.ConnectionString);
            DataTable table = auctionDA.GetEndAuctionLogByProductID(productID);
            if (table.Rows.Count != 0)
            {
                return Converts.getValueInteger("BuyerID", 0, table);
            }
            else
            {
                return 0;
            }
        }

        public Boolean InsertAuctionLog(AuctionLogTO autionLog)
        { 
            AuctionLogDA auctionLogDA=new AuctionLogDA(ObjectBA.ConnectionString);
            return auctionLogDA.InsertAuctionLog(autionLog);
        }
    }
}
